package com.jjj.springmvc.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.jjj.springmvc.interceptor.BaseInterceptor;
import com.jjj.springmvc.interceptor.TestInterceptor;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.jjj.springmvc.controller"})
public class WebConfig extends WebMvcConfigurerAdapter {
	//拦截器
    @Bean 
    BaseInterceptor firstIntercptor(){
        return new BaseInterceptor();
    }
    @Bean 
    TestInterceptor secondIntercptor(){
    	return new TestInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        //定义拦截什么请求 
       registry.addInterceptor(firstIntercptor()).addPathPatterns("/**");
       registry.addWebRequestInterceptor(secondIntercptor()).addPathPatterns("/user/**");
    }
}
